package com.jichangxiu.framework.factory;

import cn.hutool.core.util.ObjectUtil;
import com.jichangxiu.common.context.JcxContext;
import com.jichangxiu.common.entity.bo.JcxContextEntity;
import com.jichangxiu.common.entity.rule.InfoRule;
import com.jichangxiu.framework.service.InfoRuleService;
import com.jichangxiu.framework.utils.InfoRuleUtils;

import java.util.TimerTask;

public class InfoRuleAsyncFactory {

    public static TimerTask recordInfoRule(InfoRuleService infoRuleService, InfoRule infoRule) {
        JcxContextEntity jcxContextEntity = JcxContext.getJcxContextEntity();
        return new TimerTask() {
            @Override
            public void run() {
                // 插入数据
                if (ObjectUtil.isNotEmpty(jcxContextEntity) && ObjectUtil.isNotEmpty(infoRuleService) && ObjectUtil.isNotEmpty(infoRule)) {
                    InfoRuleUtils.fillLocation(infoRule);
                    infoRuleService.saveInfoRule(jcxContextEntity, infoRule);
                }
            }
        };
    }

}
